"""
场景数据初始化脚本
"""

from datetime import datetime

from sqlalchemy.orm import Session

from pojo.ai_web_scene import SceneStatus
from pojo.ai_web_scene_model import AIWebSceneModel


def init_scene_data(db: Session):
    """初始化场景数据"""

    # 检查是否已有数据
    existing_count = db.query(AIWebSceneModel).count()
    if existing_count > 0:
        print(f"场景数据已存在 {existing_count} 条记录，跳过初始化")
        return

    print("开始初始化场景数据...")

    # 创建根节点
    root1 = AIWebSceneModel(
        scene_id="root_001",
        scene_name="基础",
        description="根节点",
        parent_id=None,
        node_path="/",
        node_level=0,
        sort_order=1,
        scene_status=SceneStatus.ACTIVE,
        creator="admin",
        create_time=datetime.now()
    )
    db.add(root1)
    db.commit()
    print("场景数据初始化完成！")
